﻿// -----------------------------------------------------------------------
// <copyright file="StonglyTypedCollectionTransformerTaskHelper.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Dhgms.TplHelper.Model.TaskHelper
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Dhgms.TplHelper.Controller.Task;
    using Dhgms.TplHelper.Model.Info;
    using Dhgms.TplHelper.Model.Info.TaskResult;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public abstract class StonglyTypedCollectionTransformerTaskHelper<TProducer, TConsumer, TSourceType, TTaskResultClass, TTaskDataType> : InternalTransformerTaskHelper<TTaskResultClass, IList<TTaskDataType>>
        where TProducer : Dhgms.TplHelper.Model.StronglyTypedProducer.StronglyTypedProducerBase<IList<TSourceType>>
        where TConsumer : Dhgms.TplHelper.Model.Consumer.StrongTypedCollectionConversionConsumer<TSourceType, TTaskDataType>
        where TTaskResultClass : TaskResultBase, IReportableCount, ITaskDataResult<IList<TTaskDataType>>, new()
    {
        protected StonglyTypedCollectionTransformerTaskHelper(string name)
            : base(name)
        {
        }

        /// <summary>
        /// Gets the producer.
        /// </summary>
        /// <returns>The producer</returns>
        protected abstract TProducer GetProducer();

        /// <summary>
        /// Gets the consumer.
        /// </summary>
        /// <returns>The consumer</returns>
        protected abstract TConsumer GetConsumer();

        protected override DataRetrievalProcessorResult<IList<TTaskDataType>> OnProcess()
        {
            var producer = GetProducer();
            var consumer = GetConsumer();

            var executionResult = producer.ProduceAndConsume(consumer.Consume);

            var result = new DataRetrievalProcessorResult<IList<TTaskDataType>>(executionResult, consumer.Data);
            return result;
        }
    }
}
